from AccessControl import ModuleSecurityInfo

from Products.CMFCore import permissions
from Products.CMFCore import utils
from Products.CMFPlone.utils import ToolInit

from Products.ATContentTypes.config import HAS_LINGUA_PLONE
if HAS_LINGUA_PLONE:
    from Products.LinguaPlone.public import process_types
    from Products.LinguaPlone.public import listTypes
else:
    from Products.Archetypes.atapi import process_types
    from Products.Archetypes.atapi import listTypes

# Import "BESMessageFactory as _" to create messages in bescontenttypes domain
from zope.i18nmessageid import MessageFactory
ePubMessageFactory = MessageFactory('epub')
ModuleSecurityInfo('Products.ePub').declarePublic('ePubMessageFactory')

import Products.ePub.content
from Products.ePub.config import *

def initialize(context):
    """Initializer called when used as a Zope 2 product."""

    listOfTypes = listTypes(PROJECTNAME)

    content_types, constructors, ftis = process_types(
        listOfTypes,
        PROJECTNAME)

    allTypes = zip(content_types, constructors)
    for atype, constructor in allTypes:
        kind = "%s: %s" % (PROJECTNAME, atype.archetype_name)
        if atype not in FOLDER_TYPES:
            permission = permissions.AddPortalContent
	else:
            permission = permissions.AddPortalFolders
        utils.ContentInit(
            kind,
            content_types      = (atype,),
            permission         = permission,
            extra_constructors = (constructor,),
            ).initialize(context)